import request from '@/service/index.js'
import objectToQueryString from '@/utils/objecToQuery.js'
/** 用户的网络请求 */
// 获取所有社团
export function getAllClubs(limit, offset, status) {
	const queryString = objectToQueryString({ limit, offset, status })
	console.log(queryString);
	return request.get({
		url: `/clubs?${queryString}`
	})
}

// 创建社团
export function postCreateClub(clubInfo) {
	return request.post({
		url: '/clubs',
		data: clubInfo
	})
}

// 查询单个社团
export function getClubById(id) {
	return request.get({
		url: `/clubs/${id}`
	})
}

// 根社团名字模糊查询社团
export function getClubByName(name, limit, offset, status) {
	const queryString = objectToQueryString({name, limit, offset, status })
	console.log(queryString);
	return request.get({
		url: `/clubs/clubname?${queryString}`
	})
}

// 删除一个社团
export function deleteClubById(id) {
	return request.delete({
		url: `/clubs/${id}`
	})
}

//更新社团
export function updateClub(id, clubInfo) {
	return request.put({
		url: `/clubs/${id}`,
		data: clubInfo
	})
}

// 修改社团状态
export function updateClubStatus(id, status) {
	return request.put({
		url: `/clubs/${id}/status?status=${status}`
	})
}

// 获取单个社团的成员
export function getClubMemberByClubId(id, limit, offset, name, status) {
	let queryString = objectToQueryString({limit, offset, name, status})
	console.log(queryString, 'queryString');
	return request.get({
		url: `/clubs/${id}/members?${queryString}`,
	})
}

// 更改成员状态为active
export function reviewMemberById(club_id, id, status) {
	return request.put({
		url: `/clubs/${club_id}/members/${id}/review`,
		data: {
			status
		}
	})
}

// 修改社团成员状态
export function deleteMemberById(club_id,user_id) {
	return request.delete({
		url: `/clubs/${club_id}/members/${user_id}/remove`
	})
}

// 根据id1获取社团
export function getClubByUserId() {
	return request.get({
		url: `/clubs/leader/club`
	})
}

// 根据id查询参加了的社团
export function getJoinedClubByUserId(user_id) {
	return request.get({
		url: `/clubs/me/${user_id}`
	})
}

// 根据id获取员工状态
export function getClubMemberStatus(club_id) {
	return request.get({
		url: `/clubs/${club_id}/members/status`
	})
}

// 报名参加社团
export function joinClub(club_id) {
	return request.post({
		url: `/clubs/${club_id}/join`
	})
}

// 退出社团
export function quitClub(club_id) {
	return request.delete({
		url: `/clubs/${club_id}/members/quit`
	})
}
